package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "用户管理模块")
@RequestMapping("/admin/system/user")
public class SysUserController {
    @Resource
    SysUserService sysUserService;
    @Operation(summary = "条件分页查询用户列表")
    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result page(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                       //自定义DTO来接收前端提交的参数
//                       @RequestBody
                       // pojo入参： 获取请求参数设置给对象的相同属性 url?k=v&k2=v2
                       SysUserDto sysUserDto
                       ){
        PageInfo<SysUser> pageInfo = sysUserService.findPage(pageNum,pageSize,sysUserDto);
        return Result.ok().data(pageInfo);
    }
    @Operation(summary = "根据id删除用户")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Long id){
        sysUserService.deleteById(id);
        return Result.ok();
    }
    @Operation(summary = "批量删除用户")
    @DeleteMapping("/batchDel")
    public Result batchDel(@RequestBody List<Long> ids){
        sysUserService.batchDel(ids);
        return Result.ok();
    }
    @Operation(summary = "新增用户")
    @PostMapping("/save")
    public Result save(@RequestBody SysUser sysUser){
        sysUserService.save(sysUser);
        return Result.ok();
    }

    @Operation(summary = "根据id查询用户")
    @GetMapping("{id}")
    public Result getById(@PathVariable("id")Long id){
        SysUser sysUser = sysUserService.getById(id);
        return Result.ok().data(sysUser);
    }
    @Operation(summary = "更新用户")
    @PutMapping("/update")
    public Result update(@RequestBody SysUser sysUser){
        sysUserService.update(sysUser);
        return Result.ok();
    }

}
